<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="index.css">
</head>
<body>

</body>
<script src="index.js"></script>
<script>
    // const makePage = (total,cur,around) => {
    //     let result = [];
    //     let baseCount = around * 2 + 1 + 2 + 2 + 2; //总共元素个数
    //     let surplus = baseCount - 4; //只出现一个省略号 剩余元素个数
    //     let startPosition = 1 + 2 + around + 1;//前面出现省略号的临界点
    //     let endPosition = total - 2 - around - 1;//后面出现省略号的临界点
    //     if(total <= baseCount - 2){ //全部显示 不出现省略号
    //         result =  Array.from({length: total}, (v, i) => i + 1);
    //     }else{ //需要出现省略号
    //         if(cur < startPosition){ //1.只有后面出现省略号
    //             result = [...Array.from({length: surplus}, (v, i) => i + 1),"...",total]
    //         }else if(cur > endPosition) { //2.只有前边出现省略号
    //             result = [1,'...',...Array.from({length: surplus}, (v, i) => total - surplus + i + 1)]
    //         }else{ //3.两边都有省略号
    //             result = [1,'...',...Array.from({length: around * 2 + 1}, (v, i) => cur - around + i),'...',total]
    //         }
    //     }
    //     return result
    // }
    // console.log(makePage(112, 19, 2));
    // console.log(makePage(20, 16, 2));
    // console.log(makePage(7, 2, 2));//[1, 2, 3, 4, 5, 6, 7]
    // console.log(makePage(20, 3, 2));//[1, 2, 3, 4, 5, 6, 7, "...", 20]
    // console.log(makePage(20, 10, 2));//[1, "...", 8, 9, 10, 11, 12, "...", 20]
    // console.log(makePage(20, 19, 2));//[1, "...", 14, 15, 16, 17, 18, 19, 20]
</script>
</html>